import {CHANGE_INPUT,ADD_LIST,DEL_LIST,SET_LIST} from './actionType';
//相当于全局数据的管理者
const defaultState={
  inputValue:'请输入要做的事情。',
  list:[]
};
export default (state=defaultState,action)=>{
  //reducer里面只能接受state 不能直接改变
  if(action.type===CHANGE_INPUT){
    let newState =JSON.parse(JSON.stringify(state));
    newState.inputValue=action.value;
    return newState;
  }
  if(action.type===ADD_LIST){
    let newState =JSON.parse(JSON.stringify(state));
    newState.list.push(action.value);
    newState.inputValue='';
    return newState;
  }
  if(action.type===DEL_LIST){
    let newState =JSON.parse(JSON.stringify(state));
    newState.list=[...action.value]
    return newState;
  }
  if(action.type===SET_LIST){
    let newState =JSON.parse(JSON.stringify(state));
    newState.list=action.data;
    return newState;
  }
  return state;
}